<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="com.stone.para.IConstant"%>
<%@ page import="com.stone.sys.pojo.TUser"%>
<%
	String contextPath = request.getContextPath();
	String organname = request.getParameter("opernerName");
	String organid = request.getParameter("opernerId");
	String ouid = request.getParameter("opernerOuid");
	String opernerType = request.getParameter("opernerType");
	String loginUser = request.getParameter("loginUser") != null ? request.getParameter("loginUser") : ((TUser)session.getAttribute(IConstant.SESSION_TUSER)).getId().toString();
	
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%=IConstant.PROGRAEM_TITLE%></title>
        <link rel="stylesheet" href="<%=contextPath%>/ext3/resources/css/ext-all.css" type="text/css"   />
        <script src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
        <script src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
        <script src="<%=contextPath%>/ext3/ext-all.js"></script>
        <script language="javascript">
            Ext.BLANK_IMAGE_URL = '<%=contextPath%>/ext3/resources/images/default/s.gif';
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'qtip';
            var cpath = '<%=contextPath%>';
		
			Ext.onReady(function(){

			var storeSQ = new Ext.data.Store({
        		proxy:new Ext.data.HttpProxy({url:'userList!getListExtTree.do?state=user'}),
        		reader:new Ext.data.JsonReader({},['id','text','qtip','parentId']),
        		autoLoad:true,
        		listeners:{"load":function(store,records){
        							if (records != null && records != "") {
        							// 已选择用户
        				var arrayoldid = window.opener.document.frmM.elements["<%=organid%>"].value.trim().split(",");
										for (var i=0; i<records.length; i++){
	       									var n = new Ext.tree.TreeNode({
                								id:records[i].data.id,
                								text:records[i].data.text,
                								qtip:records[i].data.qtip,
                								leaf:true
											});//window.alert(records[i].data.parentId);
	       									// 第一层菜单时
	       									if (records[i].data.parentId == "A0") {
            									tree.root.appendChild(n);
            								// 下级菜单
	       									} else {
	       										tree.getNodeById(records[i].data.parentId).leaf = false;
	       										tree.getNodeById(records[i].data.parentId).appendChild(n);
	       									}
   										}
   										if (arrayoldid.length ==0 || (arrayoldid.length ==1 && arrayoldid[0]=="")) {
				        tree.root.expandChildNodes();
						// 变电工区展开
						tree.root.firstChild.expandChildNodes();//    tree.getNodeById("A1").expandChildNodes();
						
						tree.getNodeById("<%=loginUser%>").parentNode.expand(true);
				        tree.getNodeById("<%=loginUser%>").parentNode.expandChildNodes();
					} else {

						// root 展开
						tree.root.expandChildNodes();
						// 变电工区展开
						tree.root.firstChild.expandChildNodes();//    tree.getNodeById("A1").expandChildNodes();
						
						tree.getNodeById(arrayoldid[0]).parentNode.expand(true);
						tree.getNodeById(arrayoldid[0]).parentNode.expandChildNodes(true);
					}
   										
									} 
                    			}}
    		});

            
		/* 生成Ttee,放到tree Div里面 */
 		var tree = new Ext.tree.TreePanel({
                        id:"mytree",   
                        renderTo : "tree",
                        rootVisible:false,
                        root : new Ext.tree.TreeNode({   
                    			id : "root", 
                    			draggable:false, 
                    			singleClickExpand:true, 
                    			text : "<%=IConstant.PROGRAEM_TITLE%>"
	 						}),  
                        store : storeSQ,   
                        width : 300,   
                        height : 600,
				        useArrows:true,
				        autoScroll:true,
				        animate:true,
				        containerScroll:true,
				        listeners:{"click":function(node){ 
												if(node.attributes.qtip != '000') {
																Ext.MessageBox.alert('提示', '请选择人员');
																return;
															}
														// 参照
														try {
															window.opener.document.frmM.elements["<%=organid%>"].value = node.id;
															if(<%=opernerType%>=='1'){
														window.opener.gzapFzrCheck();
														}else{
														//window.close();	
														}
														} catch (e) {
														
														}
														try {
															window.opener.document.frmM.elements["<%=organname%>"].value = node.text;
														} catch (e) {
														
														}
														try {
														//	window.opener.document.frmM.elements["<%=ouid%>"].value = node.attributes.qtip;
														} catch (e) {
														
														}
														
														window.close();	
													
                    	}}
				});
 		});      
      function gzapFzrCheckOld() {
				Ext.Ajax.request({
					method :'POST',
					url :'gzrwd!gzapFzrCheck.do?rq='+window.opener.document.frmM.elements["entity.rq"].value+'&zbz=' + window.opener.document.frmM.elements["entity.zbz"].value,
					success : function(response) {
					var obj = Ext.decode(response.responseText);
					alert(obj["count"]+'1222');
					if (obj["count"] == "1") {alert(obj["count"]);
						Ext.MessageBox.alert('提醒', '已经安排任务是否继续安排？');
						//return false;
						window.close();
					}
					},
					failure : function() {
						alert("链接系统失败");
					}
				});
	
			}
		</script>
	</head>
	<body>
		<div id="tree" style="position:absolute;left:0px;top:0px;width:100%;height:100%;overflow:hidden;border:none">
		</div>
	</body>
</html>
